home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: newsfeed.internetmci.com!btnet!bt!btcase!Pearl
- From: muthu@mbtpost.agw.bt.co.uk (Muthu Kumar)
- Subject: Re: const usage as #define
- Message-ID: <4fujng$7o_001@agw.bt.co.uk>
- Sender: news@btcase.bt.co.uk (USENET News System)
- Organization: MBT
- X-Newsreader: News Xpress Version 1.0 Beta #4
- References: <4frc93$2s8@fmsu03.fm.intel.com>
- Date: Thu, 15 Feb 1996 06:26:56 GMT
-
- In article <4frc93$2s8@fmsu03.fm.intel.com>,
- tomtzigt@frx215.intel.com (Theodore Omtzigt - MPG MAP - FOLSOM) wrote:
- >Path:
- btcase!bt!btnet!tank.news.pipex.net!pipex!news.mathworks.com!newsfeed.internet
- mci.com!in1.uu.net!inews.intel.com!itnews.sc.intel.com!fmsu03.fm.intel.com!frx
- 215!tomtzigt
- >From: tomtzigt@frx215.intel.com (Theodore Omtzigt - MPG MAP - FOLSOM)
- >Newsgroups: comp.lang.c++
- >Subject: const usage as #define
- >Date: 14 Feb 1996 01:01:23 GMT
- >Organization: Intel Corporation
- >Lines: 33
- >Distribution: ca
- >Message-ID: <4frc93$2s8@fmsu03.fm.intel.com>
- >NNTP-Posting-Host: frx215.fm.intel.com
- >Status: N
- >
- >We are trying to port a piece of C++ code to different platforms.
- >The code was developed with GNU g++, but we would like to use
- >the native compilers that come with the different platforms.
- >On IBM we use c++, on HP we use cfront, and on NT we use VC++.
- >Now the following situation arises: given this piece of code
- >
- >class foo {
- > private:
- > const int SIZE = 10;
- > int array[SIZE];
- > public:
- > foo();
- >};
- >
- >The intend has probably been to use the 'const int SIZE' like a
- >#define macro to parameterize the static allocation of 'array'.
- >GNU g++ has no problem with this intend, and IBM c++ also accepts
- >this const initializer, but Cfront and VC++ do like the const
- >initialization. If you then try to use the foo bla : SIZE(10)
- >style to initialize the const int SIZE then you run in the
- >problem of not being able to compile int array[SIZE] appropriately.
- >
- >What is the proper C++ way of doing the above?
- >
- >Since I don't read this news group regularly, please respond directly
- >through email. Thanks in advance,
- >
- >Theo
-
-
- Use enum.
-
- class foo {
- private:
- enum { SIZE=10};
- int array[SIZE];
- public:
- foo();
- };
-
- Hope this helps.
-
-
- =~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=
- K. Muthu Kumar
- 14 Shreeji Apartments,
- Kondi Vitta Village,
- Bombay - 59.
- INDIA.
- Ph: (O) +91-22-836 78 42
- (R) +91-22-839 08 21
- Internet: muthu@mbtpost.agw.bt.co.uk
- =~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=
-